import org.rollinitiative.d20.dice.Dice;

/**
 * 
 */

/**
 * @author bebopJMM
 *
 */
public class DicePerformance {

	public static void main (String[] args) throws Exception {
		
		Dice dice = Dice.getInstance();
		int rolls[] = new int[100000];
		int counts[];
		
		long start;
		long end;
		long duration;
		float avg;
		
		System.out.println("d20 roll test, iterations = " + rolls.length);
		start = System.currentTimeMillis();
		
		int numOfDice = 3;
		int numOfSides = 6;
		int bonus = 0;
		for (int i=0; i<rolls.length; i++) {
			rolls[i] = dice.roll(numOfDice, numOfSides, bonus);
		}
		end = System.currentTimeMillis();
		duration = end - start;
		avg = (float)duration / (float)rolls.length;
		counts = new int[numOfDice*numOfSides+bonus];
		for (int i=0; i<rolls.length; i++) {
			counts[rolls[i]-1]++;
		}
		System.out.println("Total time to roll = " + duration);
		System.out.println("Avg roll time = " + avg);
		float median = (float)rolls.length / (float)counts.length;
		System.out.println ("Counts per value, median = " + median);
		// dice rolls are off by one... 0 = 1, 1 = 2, 2 = 3
		for (int i=numOfDice-1+bonus; i<counts.length; i++) {
			System.out.println("counts: " + (i+1) + " = " + counts[i]);
		}		
	}
}
